package com.enation.app.web.core.action.backend.api;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.enation.app.web.core.model.Address;
import com.enation.app.web.core.service.IAddressManager;
import com.enation.framework.action.JsonResult;
import com.enation.framework.util.JsonResultUtil;

/**
 * 
 * @function 地址api
 * @author 闯哥
 * @time 2016年12月25日 上午11:11:08
 */
@Controller
@RequestMapping("/core/admin/address")
public class AddressAPI {

	@Autowired
	private IAddressManager addressManager;

	@ResponseBody
	@RequestMapping(value = "/get-parent")
	public JsonResult getParent(Integer pid) {

		List<Address> cityList = this.addressManager.getParentByPid(pid);
		if (cityList.get(0).getId() == 0) {
			cityList.remove(0);
		}
		return JsonResultUtil.getObjectJson(cityList);
	}

	@ResponseBody
	@RequestMapping(value = "/get-area")
	public JsonResult getArea(Integer pid) {
		List<Address> list = this.addressManager.getParentByPid(pid);

		Integer parentId = list.get(0).getId();
		list.remove(0);
		List<Address> areList = this.addressManager.getParentByPid(parentId);
		for (Address address : list) {
			areList.add(address);
		}

		return JsonResultUtil.getObjectJson(areList);
	}

}
